<cfparam name="msg" default="">
<cfif len(msg) GT 0><cfoutput><strong>#msg#</strong></cfoutput><br></cfif>
<cfparam name = "start" default="1">
<cfparam name = "disp" default="100">
<cfparam name = "searchtxt" default="">
<cfparam name = "doaction" default="deafult">
<cfparam name = "addid" default="0">

<cfif doaction IS 'delete'>
	<cfquery name="qdelete" datasource="#request.dsn#">
    DELETE FROM blog_categories
    WHERE id = <cfqueryparam value="#url.id#" cfsqltype="cf_sql_integer">
    </cfquery>

	<cfquery name="qdelete" datasource="#request.dsn#">
    DELETE FROM blog_categories_map
    WHERE cid = <cfqueryparam value="#url.id#" cfsqltype="cf_sql_integer">
	</cfquery>
</cfif>

<cfif doaction IS 'add'>
	<cfinvoke component="cfcs.common.dbqueries" method="insertdata" tablename="blog_categories" returnvariable="addid" />
    <cflocation url="index.cfm?c=blog&a=categories&addid=#addid#">
</cfif>

<cfif doaction IS 'update'>
	<cfif isdefined('form.cnames') AND isdefined('form.ids')>
    	<cfloop from="1" to="#listlen(form.ids)#" index="i">
        	<cfset this_id = listgetat(form.ids, i)>
            <cfset this_cname = listgetat(form.cnames, i)>
            
            <cfquery name="qupdate" datasource="#request.dsn#">
            UPDATE blog_categories
            SET cname = '#this_cname#'
            WHERE id = <cfqueryparam value="#this_id#" cfsqltype="cf_sql_integer">
            </cfquery>
        </cfloop>
        <div id="messages">Changes have been saved.</div>        
    </cfif>
</cfif>
<script language="javascript">
function confirmdelete(id,itemname) {
	var agree=confirm("Are you sure you want to delete "+itemname+"?  This action cannot be undone!");
	if (agree) {
		location.replace('index.cfm?c=blog&a=categories&doaction=delete&id='+id); 
		}
}
</script>

<cfinvoke component="cfcs.blog" method="getcategories" returnvariable="qcats" />


<table width="700" border="0" cellspacing="0" cellpadding="6">
  <form method="post" action="index.cfm?c=blog&a=categories&doaction=add" name="newcat">
  <tr>
  	<td>Add One: <input name="cname" type="text" id="cname" value="" size="65" /></td>
    <td><input type="submit" name="submitbtn" id="abutton" value="Add" /></td>
  </tr>
  </form>
  <tr>
    <td id="columnheaders">Name</td>
    <td id="columnheaders" width="15%">&nbsp;</td>
  </tr>
<form method="post" action="index.cfm?c=blog&a=categories&doaction=update">
<cfoutput query="qcats">
  <tr class="menu_row" onMouseOver="this.className = 'menu_row_over2';" onMouseOut="this.className = 'menu_row';">
    <td <cfif NOT id IS addid>class="menu_cell"<cfelse>class="menu_cell_lastid"</cfif>><input type="hidden" name="ids" value="#id#" /><input type="text" size="45" name="cnames" value="#cname#" /></td>
    <cfset the_cname = replace(cname, "'", "", "ALL")>
    <td <cfif NOT id IS addid>class="menu_cell"<cfelse>class="menu_cell_lastid"</cfif>><div align="center"><a href = "javascript: confirmdelete('#id#', '#the_cname#');"><img src="images/delete2.png" border="0" title="Delete" alt="Delete" /></a></div></td>
  </tr>
</cfoutput>
  <tr>
  <td colspan="2"><div align="right"><input type="submit" value="Update" id="abutton" name="submitbtn" /></div></td>
  </tr>
</form>
</table>